<?php

namespace app\common\model;

use think\Model;
use think\Db;
use think\Exception;
use think\Session;

/**
 * 链接第二个数据库模型
 */
class Dbb extends Model {

    public static function getDbbConnection(){
        return Db::connect('db_b');
    }


    // 表名
    protected $name = 'teacher';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

//    // 追加属性
//    protected $append = [
//        'ctime_text',
//        'mtime_text'
//    ];


    public static function test(){
        $result = self::getDbbConnection()
            ->table('t_teacher')
            ->select();
        if($result)
            return $result;
        else
            return false;
    }


    public static function test_course(){
        $link = self::getDbbConnection();
        $res = $link->table('t_video')->field('*')->select();
        if($res){
            $name = $res;
        }else{
            $name = '';
        }
        return $name;
    }


    public  function getTeachersList(){
        $list = self::getDbbConnection()->getModel()->select();
        $list = collection($list)->toArray();
        $Arr = [];
        if($list){
            foreach($list as $k=>$v){
                $Arr[$v['id']] = $v['name'];
            }
        }
        unset($list);
        return $Arr;
    }

    public static  function test3(){
        $rs = self::getDbbConnection()->query('select * from t_exclusive limit 2');
        if($rs)
            return $rs;
        else
            return false;
    }


}
